/*************************************************************************
*  TIMER Funktionen des ATMega8 im RDS Versuchsstand
*
*  contact: sebastian.trommer@gmail.com
*  homepage: wiki.car2.de
*
*  Revision History
*
*  when         what  who	why
*  2009-02-24	0.10  TSE	initial
*  2009-03-13	0.11  TSE	Vorberietungen zur Ersterprobung auf Controller
*
**************************************************************************/
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/twi.h>

#include "timer.h"
#include "functions.h"

void TIMER_init() {

	// set PB1 as output
	DDRB &= (1 << PB1);
	// init Timer 2
	TCCR2 |= ((0<<CS02)|(0<<CS01)|(1<<CS00)|(1<<WGM21)|(0<<WGM20)|(1<<COM20)|(0<<COM21));
	// init Timer 1 in CTC mode
	TCCR1B |= (0<<WGM13)|(1<<WGM12)|(0<<WGM11)|(0<<WGM10);
	// activate interrupt
	TIMSK |= (1 << OCIE1A)|(1 << OCIE1B)|(1 << OCIE2);
	// counter value
	OCR1A = 255;
	OCR2 = 255;
	// no prescaler
	TCCR1B |= ((0 << CS12)|(0 << CS11)|(1 << CS10));
	// toggle OC1A if Timer = counter valua
	TCCR1A |= (0<<COM1A1)|(1 << COM1A0);
}
